package com.example.soap.endpoint;

import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import com.example.soap.config.Global;
import com.example.soap.model.AddClassInfoRequest;
import com.example.soap.model.AddClassInfoResponse;
import com.example.soap.model.ClassInfo;
import com.example.soap.model.GetClassInfoRequest;
import com.example.soap.model.GetClassInfoResponse;
import com.example.soap.model.Sex;
import com.example.soap.model.StudentInfo;

/**
 * 端点业务代码
 *
 * @author LiuGangQiang Create in 2025/09/04
 */
@Endpoint
public class SoapDemoEndpoint {

    @PayloadRoot(namespace = Global.NAMESPACE_URI, localPart = "GetClassInfoRequest")
    @ResponsePayload
    public GetClassInfoResponse getClassInfo(@RequestPayload GetClassInfoRequest request) {
        GetClassInfoResponse response = new GetClassInfoResponse();
        ClassInfo info = new ClassInfo();
        StudentInfo stu1 = new StudentInfo();
        stu1.setName("张三");
        stu1.setNo("A001");
        stu1.setAge(12);
        stu1.setSex(Sex.MALE);

        StudentInfo stu2 = new StudentInfo();
        stu2.setName("李四");
        stu2.setNo("A002");
        stu2.setAge(15);
        stu2.setSex(Sex.FEMALE);

        StudentInfo stu3 = new StudentInfo();
        stu3.setName("王五");
        stu3.setNo("A003");
        stu3.setAge(16);
        stu3.setSex(Sex.MALE);

        info.getStudents().add(stu1);
        info.getStudents().add(stu2);
        info.getStudents().add(stu3);
        info.setName("瓦力班");
        info.setRemark("这是一个幼儿园");

        response.setClassInfo(info);
        return response;
    }

    @PayloadRoot(namespace = Global.NAMESPACE_URI, localPart = "AddClassInfoRequest")
    @ResponsePayload
    public AddClassInfoResponse addClassInfo(@RequestPayload AddClassInfoRequest request) {
        AddClassInfoResponse response = new AddClassInfoResponse();
        response.setMessage("添加成功");
        response.setSuccess(true);
        return response;
    }
}
